package com.wushijia.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "user")
@Setter
@Getter
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})
public class User implements java.io.Serializable {

  private static final long serialVersionUID = 1L;

  @Id
  @GenericGenerator(name = "id", strategy = "uuid")
  @GeneratedValue(generator = "id")
  private String id;

  private String nickname;//用户昵称/别名
  @NotNull
  @Column(name = "username")
  private String username;
  private String password;
  private String email;

  @JsonIgnore
  @ManyToOne
  @JoinColumn(name = "role_id")
  private Role role;

  private String mobile;//扩展联系方式
  private String lastip;//最后登录ip
  private Date lastLoginTime;//最后登录时间
  private String gender;//性别
  @Column(name = "head_url")
  private String headUrl;//头像
  private String address;
  private String status;//用户状态
  private String type;//用户类型枚举：SICodeEnum
  private String isLocked;//账号是否被锁定
  private String serial;

  public User() {
    super();
  }

  public User(User u) {
    id = u.getId();
    nickname = u.getNickname();
    email = u.getEmail();
    username = u.getUsername();
    mobile = u.getMobile();
    lastip = u.getLastip();
    password = u.getPassword();
    lastLoginTime = u.getLastLoginTime();
    gender = u.getGender();
    address = u.getAddress();
    status = u.getStatus();
    type = u.getType();
    isLocked = getIsLocked();
    serial = u.getSerial();
  }
}
